import moment from 'moment'
import store from '@/store'

export const deepClone = obj => {
  return JSON.parse(JSON.stringify(obj)) // 深拷贝
}

export const formatMonth = timestamp => {
  // const date = new Date(Number(timestamp))
  // const YYYY = date.getFullYear()
  // const MM = date.getMonth()
  // return `${YYYY}-${MM}`
  return moment(timestamp).format('YYYY-MM')
}

export const formatDate = timestamp => {
  return moment(timestamp).format('YYYY-MM-DD hh:mm:ss a')
}

export const getRoleById = id => {
  const { roleList } = store.state
  const result = roleList.find(item => item._id === id)
  return result ?? { title: '游客' }
}
